<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import {confirmModal, ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import urlUtil from "@/static/js/urlUtil.js"
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				teacherCacheKey:"hr-train-trainotice-title2-teacher-cache",
				placeCacheKey:"hr-train-trainotice-title2-place-cache",
				userCacheKey:'hr-train-trainotice-title2-user-cache',
				ability:""
			})
		},
		methods:{
			verifyTeacher(id,ability){
				let _that = this 
				_that.om.request(
					"trainNotice/verifyTeacher",
					{	
						userId:id,
						relevantAbilityIdStr:ability
					},
					'post'
				).then(res=>{
					if(!res.value.flag){
						confirmModal(
							_that,
							'提示信息',
							res.value.confirmMsg,
							function() {
							},
							function() {
								_that.$refs.autoform.clear("title2","teacherId")
								return false;
							}
						);
					}
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.teacherCacheKey,
					success:(res)=>{
						let d = res.data[0]
						let formdata = _that.$refs.autoform.formdata
						formdata.teacherId = d.id
						formdata.teacherName = d.username
						_that.verifyTeacher(d.id,_that.ability)
						uni.removeStorage({
							key:_that.teacherCacheKey
						})
					}
				})
				uni.getStorage({
					key:_that.placeCacheKey,
					success:(res)=>{
						let d = res.data
						let formdata = _that.$refs.autoform.formdata
						formdata.placeId = d.id
						formdata.placeName = d.dicname
						uni.removeStorage({
							key:_that.placeCacheKey
						})
					}
				})
				uni.getStorage({
					key:_that.placeCacheKey,
					success:(res)=>{
						let d = res[0].data
						let formdata = _that.$refs.autoform.formdata
						formdata.userId = d.id
						formdata.userName = d.dicname
						uni.removeStorage({
							key:_that.placeCacheKey
						})
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				_that.ability = e.relevantAbilityIdStr
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("title2","userId","isSearchUser",true,_that.autoformdata)
							changeEditor("title2","userId",{
								link:'../../public/searchUser/searchUser',
								"linkParam":{
									cachename: _that.userCacheKey,
									isSingle:true
								}
							},null,_that.autoformdata),
							changeEditor("title2","teacherId","isSearchUser",true,_that.autoformdata)
							changeEditor("title2","teacherId",{
								"link": '/pages/public/searchUser/searchUser',
								"linkParam":{
									other:JSON.stringify({
										firstUserId: ''
									}),
									label: urlUtil.officePageUrl().namefield,
									label2:'username',
									searchfield: 'q',
									initload: true,
									paging:true,
									isSingle:true,
									url: 'temployee/getStaffCombogrid',
									cachename: _that.teacherCacheKey
								}
							},null,_that.autoformdata)
							changeEditor("title2","placeId",{
								"link": '/pages/public/pageSearch/pageSearch',
								"linkParam":{
									other:JSON.stringify({
										code:"37967"
									}),
									namefield:"dicname" ,
									searchfield: "q",
									initload:true,
									url:"tsysdict/getCombobox",
									cachename: _that.placeCacheKey,
									pagination: true
								}
							},null,_that.autoformdata)

							}
						}
					})
				}
							
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
